<template>
	<view class="waikuang">
		<view class="mdxx" @click="goshangjxx">
			<view class="mdxinx">
				<view>今日业绩</view>
				<view class="dizhi">
					<view class="dizhi">服务人数7人，收入340元</view>
				</view>
			</view>
			<!-- <image class="chakan" src="../../static/go.png"></image> -->
		</view>
		<view class="paiduiqk">
			<view class="arrange_list_imaeg" v-if="dqpaid.length==0">
				<image src="../../static/image/empty.png" />
				<view class="wenzi">暂时没有数据哦</view>
			</view>
			<view class="paidqk" v-else>
				<view :class="fal.fwzt==1?'paihao dqyh':'paihao paid'" v-for="fal in dqpaid" :key="fal.id">
					<view class="jbxx">
						<view class="xingm">
							{{fal.kehu.name==null||fal.kehu.name=='undefind'||fal.kehu.name==''?'李某某':fal.kehu.name}}
						</view>
						<!-- <view>{{fal.ximgm}}</view> -->
						<view>剪头发</view>
					</view>
					<view class="shouk" v-if="fal.fwzt==1" @click="send(fal.id, 3,fal.ddid)">过号</view>
					<view class="shouk" v-if="fal.fwzt==1" @click="send(fal.id, 2,fal.ddid)">完成并收款</view>
					<view class="fuwu" v-if="fal.fwzt==0" @click="send(fal.id, 1,fal.ddid)">开始服务</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dqxz: 0,
				kuan: '1100rpx',
				dqpaid: [], //排队订单的数据
				kehu_id: '', //客户ID
				paytype_id: '', //支付方式
				paytypeName: '', //支付名称
				money: 30, //消费金额
				ddlx: 0, //0是理发消费，1是商城消费、
				chishu:2 ,//年卡消费点数
				kaid:'',//年卡消费卡号
				yearCardData:[],//年卡数据
				order_id:'',
				zt:'',
				mendian_id:''
				
			}
		},
		onLoad() {
			var that = this;
			uni.getStorage({
				key: 'user_key',
				complete: function(res) {
					// console.log(666,res)
					that.mendian_id = res.data.mendian;
				}
			})
		},
		onShow() {
			this.getDqpaid();
		},
		methods: {
			//获取订单数据
			getDqpaid() {
				uni.request({
					url: getApp().globalData.url + '/client/GetLfsPdui',
					data: {
						lfsid: uni.getStorageSync('user_key').id,
						// lx: "",
					},
					method: "GET",
					header: {
						"Content-Type": "application/json"
					},
					success: (res) => {
						console.log(999, res);
						if (res.data.code == 200) {
							this.dqpaid = [];
							this.dqpaid = res.data.data;
							this.$forceUpdate()
							// this.dqpaid.forEach((item, index) => {
							// 	if (item.kehu.id == this.userInfo.id) {
							// 		this.myPdIndex = index;
							// 		this.$forceUpdate()
							// 	}
							// })
						}
					}
				})
			},
			//消单操作
			send(order_id, zt, ddid) {
				let that = this;
				if (zt == 2) {
					// 允许从相机和相册扫码
					uni.scanCode({
						success: function(res) {
							console.log('条码类型：' + res.scanType);
							console.log('条码内容：' + res.result);
							var vars = res.result.split(",");
							that.kehu_id = vars[0]
							that.paytype_id = vars[1]
							that.paytypeName = vars[2]
							if (that.paytype_id == 1 && that.paytypeName == '余额支付') {
								that.order_id=order_id;
								that.zt= zt;
								that.balancePay(ddid);
							}
							if (that.paytype_id == 2 && that.paytypeName == '年卡支付') {
								that.order_id=order_id;
								that.zt= zt;
								that.getYearCard(ddid);
								
							}
						}
					});
				} else {
					that.updateOrder(order_id, zt)
				}
			},
			//获取用户年卡
			getYearCard(ddid){
				let that = this;
				uni.request({
					url: getApp().globalData.url + '/client/GetNklist',
					data: {
						id:that.kehu_id,
					},
					method: "GET",
					header: {
						"Content-Type": "application/json"
					},
					success: (res) => {
						// console.log(999, res);
						if (res.data.code == 200&&res.data.msg=='查询成功') {
							that.yearCardData=res.data.data
							for (var i = 0; i < that.yearCardData.length; i++) {
								if(that.yearCardData[i].chishu!==null&&that.yearCardData[i].chishu!=null&&that.yearCardData[i].chishu!='undefind'&&that.yearCardData[i].chishu>1){
									that.kaid=that.yearCardData[i].kaid;
									that.chishu=that.yearCardData[i].chishu;
								}
							}
							that.yeaCcardPay(ddid)
						}
					}
				})
			},
			// //年卡消单
			yeaCcardPay(ddid) {
				let that = this;
				uni.request({
					url: getApp().globalData.url + '/client/NiankXfei',
					data: {
						id: that.kehu_id,
						chishu: that.chishu,
						ddid: ddid,
						kaid: that.kaid
					},
					method: "POST",
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					success: (res) => {
						// console.log(444, res);
						if (res.data.code == 200 && res.data.msg == '支付成功') {
							that.updateOrder(that.order_id, that.zt);
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: res.data.msg
							});
							that.getDqpaid();
						}
					}
				})
			},
			//余额消单
			balancePay(ddid) {
				let that = this;
				uni.request({
					url: getApp().globalData.url + '/client/YuerXfei',
					data: {
						id: that.kehu_id,
						money: that.money,
						ddid: ddid,
						ddlx: that.ddlx
					},
					method: "POST",
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					success: (res) => {
						// console.log(444, res);
						if (res.data.code == 200 && res.data.msg == '支付成功') {
							that.updateOrder(that.order_id, that.zt);
							uni.showToast({
								icon: 'none',
								position: 'center',
								title: res.data.msg
							});
							that.getDqpaid();
						}
					}
				})
			},
			//修改订单状态
			async updateOrder(order_id, zt) {
				uni.request({
					url: getApp().globalData.url + '/client/SetLfdd',
					data: {
						id: order_id,
						zt: zt,
					},
					method: "POST",
					header: {
						"Content-Type": "application/x-www-form-urlencoded"
					},
					success: (res) => {
						// console.log(777, res);
						if (res.data.code == 200) {
							this.getDqpaid();
						}
					}
				})
			},
			xzfxshi(xid) {
				this.dqxz = xid
			},

			// 商家信息
			goshangjxx() {
				uni.navigateTo({
					url: '../shangjxx/shangjxx?id='+this.mendian_id
				})
			}
		}
	}
</script>

<style>
	page {
		background: #f0f0f0;
	}
</style>
<style lang="scss" scoped>
	.waikuang {
		width: 710rpx;
		padding: 20rpx;

		.mdxx {
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #ffffff;
			padding: 20rpx;
			border-radius: 20rpx;

			.mdtup {
				width: 100rpx;
				height: 100rpx;
				border-radius: 10rpx;
			}

			.mdxinx {
				width: 510rpx;
				margin-left: 20rpx;

				.dizhi {
					display: flex;
					align-items: center;
					font-size: 25rpx;
					color: #828282;
					margin-top: 10rpx;

					.dizhtp {
						width: 30rpx;
						height: 30rpx;
					}

					.dizhi {
						width: 450rpx;
						display: block;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
				}
			}

			.chakan {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.paiduiqk {
			border-radius: 20rpx;
			padding: 20rpx;
			background: #ffffff;
			margin-top: 20rpx;

			.paidqk {
				width: 670rpx;
				border-top: solid 1rpx #d1d1d1;

				.dqyh {
					background: #ffb8ea;
					color: #ff007f;
				}

				.paid {
					background: #e5e5e5;
					color: #595b5f;
				}

				.my {
					background: #d2eae2;
					color: #719c93;
				}

				.mypai {
					margin-top: 20rpx;
					border-radius: 40rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					padding: 20rpx 40rpx;
					font-size: 28rpx;
					background: #ff007f;
					color: #ffffff;
				}

				.paihao {
					margin-top: 20rpx;
					border-radius: 40rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 20rpx 40rpx;
					font-size: 28rpx;

					.jbxx {
						display: flex;
						align-items: center;

						.xingm {
							font-weight: bold;
							margin-right: 10rpx;
						}
					}

					.shouk {
						background: #ff0000;
						color: #ffffff;
						width: 180rpx;
						height: 50rpx;
						border-radius: 25rpx;
						display: flex;
						justify-content: center;
						align-items: center;
					}

					.fuwu {
						background: #00aaff;
						color: #ffffff;
						width: 180rpx;
						height: 50rpx;
						border-radius: 25rpx;
						display: flex;
						justify-content: center;
						align-items: center;
					}
				}
			}

			.arrange_list_imaeg {
				height: 300rpx;
				text-align: center;
				margin-top: 200rpx;

				image {
					height: 300rpx;
					width: 350rpx;
				}

				.wenzi {
					height: 30rpx;
					text-align: center;
					font-size: 26rpx;
					color: #000;
				}
			}

			.xingxtq {
				width: 670rpx;

				.gundong {
					display: flex;
					padding-right: 20rpx;

					// width: 200rpx;
					.jvzhong {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						margin-bottom: 20rpx;

						.jtcx {
							width: 0rpx;
							height: 0rpx;
							border-top: 25rpx solid #ff007f;
							border-right: 25rpx solid transparent;
							border-left: 25rpx solid transparent;
							margin-left: 20rpx;
						}

						.jtyc {
							width: 0rpx;
							height: 0rpx;
							border-top: 25rpx solid #ffffff;
							border-right: 25rpx solid transparent;
							border-left: 25rpx solid transparent;
							margin-left: 20rpx;
						}

						.shejisk {
							width: 160rpx;
							padding: 20rpx;
							border-radius: 20rpx;
							margin-left: 20rpx;
							text-align: center;
							font-size: 30rpx;

							.fximg {
								width: 120rpx;
								height: 120rpx;
								border-radius: 60rpx;
							}

							.fxname {
								font-size: 28rpx;
								color: #808080;
								margin-top: 5rpx;
							}
						}

						.yixz {
							background-color: #ff007f;
							color: #ffffff;
						}

						.wxz {
							background-color: #efefef;
						}
					}

				}


			}
		}
	}
</style>
